package net.melon.order.inst.struts2;

import javax.annotation.Resource;

import net.esj.basic.exception.MelonException;
import net.esj.basic.utils.view.BaseJsonMessage.MessageLevel;
import net.esj.basic.view.AbstractPluginPageAction;
import net.melon.order.inst.service.OrderService;
import net.melon.order.pojo.Order;
import net.melon.order.pojo.Order.OrderState;
import net.melon.product.inst.service.impl.ClassifyCacheProxy;
import net.melon.product.pojo.ProductClassify;

public class OrderAction extends AbstractPluginPageAction<Order, Order>{

	/**
	 * 
	 */
	private static final long serialVersionUID = -7024129309393341791L;
	
	@Resource
	private ClassifyCacheProxy classifyCacheProxy;
	
	@Resource
	private OrderService orderService;
	
	private String remarks;
	
	@Override
	protected void afterQueryPage() {
		for(Object object : pagination.getRows()){
			Order order = (Order) object;
			ProductClassify classify = classifyCacheProxy.getClassify(order.getProduct().getClassifyId());
			order.getProduct().setClassify(classify);
		}
	}
	
	
	public void putCar(){
		try {
			orderService.putCar(id);
		    writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), addSuccMsg(), MessageLevel.INFO, "html");
		} catch (MelonException e) {
			writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), e.getMessage(), MessageLevel.ERROR, "html");
		} catch (Exception e) {
			writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), e.getMessage(), MessageLevel.ERROR, "html");
		}
	}
	
	public void remarks(){
		try {
			orderService.remarks(id,remarks);
		    writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), addSuccMsg(), MessageLevel.INFO, "html");
		} catch (MelonException e) {
			writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), e.getMessage(), MessageLevel.ERROR, "html");
		} catch (Exception e) {
			writeBaseJsonMessage(getText(SYSTEM_MESSAGE_TITLE,""), e.getMessage(), MessageLevel.ERROR, "html");
		}
	}
	
	public OrderState[] getStates(){
		return OrderState.values();
	}
	
	public Order getEntity(){
		return entity;
	} 
	
	public void setEntity(Order order){
		this.entity = order;
	}


	public String getRemarks() {
		return remarks;
	}


	public void setRemarks(String remarks) {
		this.remarks = remarks;
	}

}
